/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 12/8/13
 * Time: 10:14 PM
 * To change this template use File | Settings | File Templates.
 */
package com.societyGames.robotsExercises
{
import flash.display.DisplayObject;
import flash.display.Sprite;

public class RobotImage extends Sprite
{
  [Embed(source="../../../../../RobotExercises/assets/RobotSad.png")]
  private static var RobotClass:Class;

  [Embed(source="../../../../../RobotExercises/assets/RobotHappy.png")]
  private static var RobotHappyClass:Class;

  private var _robotSadImage:DisplayObject;
  private var _robotHappyImage:DisplayObject;

  public function RobotImage()
  {
    this._robotSadImage = new RobotClass();
    this._robotHappyImage = new RobotHappyClass();

    showSad();
  }

  public function showSad():void
  {
    this.removeChildIfPresent(this._robotHappyImage);
    this.addChild(this._robotSadImage);
  }

  public function showHappy():void
  {
    this.removeChildIfPresent(this._robotSadImage);
    this.addChild(this._robotHappyImage);
  }

  private function removeChildIfPresent(displayObject:DisplayObject):void
  {
    if (this.contains(displayObject))
    {
      this.removeChild(displayObject);
    }
  }
}
}
